package ssm.service;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import ssm.dao.TrackFace;
import ssm.model.TrackFaceMapper;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class TrackFaceServiceImpl implements  TrackFaceService {

    @Autowired
    private TrackFaceMapper trackFaceMapper;

    public List<TrackFace> get() {
        List<TrackFace> faces = trackFaceMapper.get();
        return faces;
    }

    public Map<String,Object> getByTimeOrJid(List<String>list,String jid,String starttime, String endtime,Integer page,Integer pageNum,Integer lx,String name) {
        Map<String,Object> map=new HashMap<String,Object>();
        if(jid!=null&&!jid.equals("")){
            map.put("jid",jid);
        }
        if(name!=null&&!name.equals("")){
            map.put("name",name);
        }
        if(!list.isEmpty()){
            map.put("list",list);
        }
        map.put("starttime",starttime);
        map.put("endtime",endtime);
        if(page!=-1&&pageNum!=0){
            int pageStart=(page)*pageNum;
            map.put("pageStart", pageStart);
            map.put("pageEnd", pageNum);
        }
        if(lx!=null&&!"".equals(lx)){
            map.put("lx",lx);
        }
        System.out.println(map);
        List<Map> faces= trackFaceMapper.getByTimeOrJid(map);
//        System.out.println(faces);
        int total=trackFaceMapper.getTotal(map);
//        System.out.println(total);
        Map<String,Object>result=new HashMap<String,Object>();
        result.put("data",faces);
        result.put("total",total);
        return result;
    }

    public Map<String, Object> getOutSchoolByFace(List<String> list, String starttime, String endtime, int page,int pageNum) {
        Map<String,Object> param=new HashMap<String,Object>();
        if(!list.isEmpty()){
            param.put("list",list);
        }
        param.put("starttime",starttime);
        param.put("endtime",endtime);
        if(page!=-1&&pageNum!=0){
            int pageStart=(page)*pageNum;
            param.put("pageStart", pageStart);
            param.put("pageEnd", pageNum);
        }
        Long time=System.currentTimeMillis();
        List<Map>faces=trackFaceMapper.getOutSchool(param);
        System.out.println("18条数据查询时间:"+(System.currentTimeMillis()-time));
        time=System.currentTimeMillis();
        int total=trackFaceMapper.getOutSchoolTotal(param);
        System.out.println("数据总和查询时间:"+(System.currentTimeMillis()-time));
        Map<String,Object>result=new HashMap<String,Object>();
        result.put("data",faces);
        result.put("total",total);
        return result;
    }

    @Override
    public Map<String, Object> getByTimeOrJid(List<String> list, String jid, String starttime, String endtime, Integer page, Integer pageNum, String name) {
        Map<String,Object> map=new HashMap<String,Object>();
        if(jid!=null&&!jid.equals("")){
            map.put("jid",jid);
        }
        if(name!=null&&!name.equals("")){
            map.put("name",name);
        }
        if(!list.isEmpty()){
            map.put("list",list);
        }
        map.put("starttime",starttime);
        map.put("endtime",endtime);
        if(page!=-1&&pageNum!=0){
            int pageStart=(page)*pageNum;
            map.put("pageStart", pageStart);
            map.put("pageEnd", pageNum);
        }
        System.out.println(map);
        List<Map> faces= trackFaceMapper.getByTimeOrJid(map);
//        System.out.println(faces);
        int total=trackFaceMapper.getTotal(map);
//        System.out.println(total);
        Map<String,Object>result=new HashMap<String,Object>();
        result.put("data",faces);
        result.put("total",total);
        return result;

    }
}
